package com.withouther.robot.rainingrobot.util.ai.dialogue;

import com.aliyuncs.exceptions.ClientException;
import com.withouther.robot.rainingrobot.util.ai.dialogue.model.BotResult;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName RobotFactory
 * @Auther: tzq
 * @Date: 2020/9/21 15:10
 * @Description:
 */
public class RobotFactory {

    private static RobotFactory tools = null;

    private static Map<Integer, DialogueBot> strategyMap = new HashMap<>();

    /**
     * 阿里云小蜜
     */
    public static final int BEEBOT = 1;

    static {
        strategyMap.put(BEEBOT, new BeeBot());
    }

    private RobotFactory() {
        init();
    }

    /**
     * 该类的初始化方法
     */
    public void init() {

    }

    /**
     * 重置该类
     */
    public void reset() {
        init();
    }

    /**
     * 工厂方法，返回
     *
     * @return
     */
    public static RobotFactory getFactory() {
        if (tools == null) {
            create();
        }
        return tools;
    }

    /**
     * 线程安全的创建方法，防止并发多次创建
     */
    private static synchronized void create() {
        if (tools == null) {
            tools = new RobotFactory();
        }
    }

    public BotResult botAction(Map<String, Object> paramMap, int type) throws ClientException {
        DialogueBot dialogueBot = strategyMap.get(type);
        return dialogueBot.getDialogue(paramMap);
    }
}
